<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>success</title>
<script src="https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js"></script>
<script language="javascript">
	function parseJson(){
		 var jsonranklist="[{\"xlid\":\"cxh\",\"xldigitid\":123456,\"topscore\":2000,\"topplaytime\":\"2009-08-20\"},{\"xlid\":\"zd\",\"xldigitid\":123456,\"topscore\":1500,\"topplaytime\":\"2009-11-20\"}]";
		 var obj = JSON.parse(jsonranklist);
		 console.log(obj);
		 console.log(obj[0].xlid);
	}
	function parseXML(){
		 var xml="<?xml version=\"1.0\" encoding=\"utf-8\" ?><DongFang>111<Company><cNname id=\"haha\">1</cNname><cIP>1</cIP></Company><Company><cNname>2</cNname><cIP>2</cIP></Company><Company><cNname>3</cNname><cIP>3</cIP></Company></DongFang>"
		 var xmlDoc = null;
		 if(window.DOMParser){
			// 其他浏览器
			 var parser = new DOMParser();
			 xmlDoc = parser.parseFromString(xml,"application/xml");
		 }else{
			// IE浏览器
			 var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
			 xmlDoc.async = false;
			 xmlDoc.loadXML(xml);
		 }
		 console.log(xmlDoc);
		 console.log(xmlDoc.xmlEncoding);
//		 console.log(xmlDoc.getElementsByTagName("DongFang")[0].firstChild.nodeValue);
//		 console.log(xmlDoc.getElementsByTagName("DongFang")[0].childNodes[0].nodeValue);
		 
		 var elements = xmlDoc.getElementsByTagName("Company");
		 for (var i = 0; i < elements.length; i++) {
		     var name = elements[i].getElementsByTagName("cNname")[0].firstChild.nodeValue;
		     var id = elements[i].getElementsByTagName("cNname")[0].id;//获取属性
		     var ip = elements[i].getElementsByTagName("cIP")[0].firstChild.nodeValue;               
		     console.log(name);
		     console.log(ip);
		     console.log(id);
		 }
	}
	$(function(){
		//js解析json数据和xml数据获取其中字段和节点信息
		parseJson();
		parseXML();
	})
	
</script>
</head>
<body>
success!
<h1>用戶名：${user.username }</h1>
<h1>密碼：${user.password }</h1>
</body>
</html>